import org.junit.*;
import java.util.*;
import play.test.*;
import models.*;
import controllers.*;


public class getUsersWithPermission extends UnitTest {
	
	@SuppressWarnings("deprecation")
	@Test
	public void testGetUsersWithPermissionEmpty() 
	{
		List<User> u = Users.getUsersWithPermission("leave project", 1l);
		assertNull(u);
		
		Action action1 = new Action ("leave project","").save();
		Action action2 = new Action ("join project","").save();
		Role registeredUser = new Role("Registered User", true).save();
        registeredUser.actions.add(action2);
        registeredUser.save();
        Project GUCMafia = new Project("GUCMafia", "bla", true).save();
        User salem = new User("Salem", "sayed", "Abdel Gawad","salemsayed", "123", "salemsayed@gmail.com", "0101420501","84 bla", "Cairo", "Egypt", "").save();
        new UserRoleProject(true, salem, registeredUser, GUCMafia).save();
        List<User> u2 = Users.getUsersWithPermission("leave project", GUCMafia.id);
        assertNull(u2);
	}
	
	@SuppressWarnings("deprecation")
	@Test
	public void testGetUsersWithPermissionNoTEmpty() 
	{
		Action action1 = new Action ("leave project","").save();
		Action action2 = new Action ("join project","").save();
		Role developer = new Role("Developer", true).save();
		Role registeredUser = new Role("Registered User", true).save();
		developer.actions.add(action1); 
        developer.actions.add(action2);
        developer.save();
        registeredUser.actions.add(action2);
        registeredUser.save();
        Project GUCMafia = new Project("GUCMafia", "bla", true).save();
        User rana = new User("Rana", "123", "Morsy", "r257", "password1","r257@hotmail.com", "1234", "15", "1254", "1325", "1").save();
        new UserRoleProject(true, rana, developer, GUCMafia).save();
        User salem = new User("Salem", "sayed", "Abdel Gawad","salemsayed", "123", "salemsayed@gmail.com", "0101420501","84 bla", "Cairo", "Egypt", "").save();
        new UserRoleProject(true, salem, registeredUser, GUCMafia).save();
        List<User> u = Users.getUsersWithPermission("leave project", GUCMafia.id);
		assertNotNull(u);
	}
}
